const SFCScriptBlock = require('@vue/compiler-sfc')
const SFCDescriptor = require('@vue/compiler-sfc')
const {relTSType} = require("./relTSType");

/**
 * 解析ts类型别名
 * @param {SFCScriptBlock} scriptBlock vue解析后的Script块
 * @param {SFCDescriptor} descriptor vue格式化后的代码
 * @return {{[string]: string}|null}
 */
function relTypeAlias(scriptBlock, descriptor) {
    const typeMap = {}
    if (scriptBlock.scriptSetupAst) {
        for (let scriptSetupAstElement of scriptBlock.scriptSetupAst) {
            if (scriptSetupAstElement.type === 'TSTypeAliasDeclaration') {
                typeMap[scriptSetupAstElement.id.name] = relTSType(scriptSetupAstElement.typeAnnotation, descriptor.scriptSetup.content)
            }
        }
    }
    if (Object.keys(typeMap).length > 0) {
        return typeMap
    }
    return null
}

exports.relTypeAlias = relTypeAlias;
